home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 60 / bin / as.doc next >
Encoding:
Text File  |  1987-08-12  |  5.3 KB  |  147 lines

  1. The syntax of the intermediate code is a terse form of assembler.
  2. This saves space, makes the assembler/loader quicker, and allows
  3. one to create "object" modules with a regular text editor.  The 
  4. drawback is that it takes more space than typical object code.
  5. Basically, every line maps into one or more 68000 instructions.  
  6. I have listed here all the codes, their 68000 assembler equivalent, 
  7. and a brief comment.  Some notes at the end explain labels, 
  8. strings, and operations (e.g. add, sub, etc).
  9.  
  10. # everything on a line after the # is a comment and ignored
  11.  
  12. : sym            define a text symbol
  13. . sym val        define a bss symbol; val is number of bytes needed
  14. * lbl            define a label (see notes)
  15. $ str            define a string (see notes)
  16. = num            word value in text space
  17. =. sym            address value in text space
  18. =$ str            string address in text space
  19. ? sym            remove the symbol from symbol table (for static)
  20.  
  21. csv            link A6,#stk        set frame and stack pointer
  22. ret            unlk A6;rts        return from function
  23. efn stk                        end of function, stk becomes
  24.                                                  the constant for csv
  25.  
  26. rsv reglst        movem reglist,-(A7)    push active registers
  27. rst regpat        movem (A7)+,reglist    pop active registers
  28. rs[wl] x off        move.[wl] Ax,off(A6)    save register variable
  29. rr[wl] off x        move.[wl] off(A6),Ax    restore register variable
  30.  
  31. cse num lbl        cmpi.l #num,D0        compare for case statements
  32. brc op lbl        bcc lbl            branch on condition (see notes)
  33. jmp lbl            bra lbl            unconditional branch
  34. jsr sym            jsr sym            direct function call
  35. jsi x            jsr (Ax)        indirect function call
  36. trp num            trap #num        trap instruction
  37.  
  38. pop num            adda.l #num,A7        pop stuff off the stack
  39. ph[wl] x        move.[wl] Dx,-(A7)    push a value on the stack
  40. pl[wl] x        move.[wl] (A7)+,Dx    pull a value off the stack
  41. pha x            move.l Ax,-(A7)        push an address on stack
  42. pla x            move.l (A7)+,Ax        pull an address off stack
  43. tad x y            move.l Ax,Dy        transfer Areg to Dreg
  44. tda x y            move.l Dx,Ay        transfer Dreg to Areg
  45. tdd x y            move.l Dx,Dy        transfer Dreg to Dreg
  46.  
  47. ld[wl] num d        move.[wl] #num,Dd    load value
  48. ll[bwl] off d        move.[bwl] off(A6),Dd    load local variable
  49. lg[bwl] sym d        move.[bwl] sym,Dd    load global variable
  50. lx[bwl] a i d        move.[bwl] 0(Aa,Di),Dd    load indexed value    
  51. lo[bwl] a off d        move.[bwl] off(Aa),Dd    load indirect with offset
  52. l$ str a        lea #str,Aa        load string address
  53. lag sym a        lea sym,Aa        load global address
  54. lal off a        lea off(A6),Aa        load local address
  55. lax a i x        lea 0(Aa,Di),Ax        load indexed address
  56. lao a off x        lea off(Aa),Ax        load address of indirect offset
  57.  
  58. ob[bwl] op x y        xxx.[bwl] Dx,Dy        binary operation (see notes)
  59. ou[bwl] op x        xxx.[bwl] Dx        unary operation (see notes)
  60.  
  61. so[bwl] a off d        move.[bwl] Dd,off(Aa)    store indirect with offset
  62. sg[bwl] d sym        move.[bwl] Dd,sym    store global
  63. sl[bwl] d off        move.[bwl] Dd,off(A6)    store local
  64. sx[bwl] a i d        move.[bwl] Dd,0(Aa,Di)    store indexed value
  65.  
  66. ad[bwl] num d        various    opcodes        multiply Dd by num, long result
  67.  
  68. cm[bwl] x y        cmp.[bwl] Dx,Dy        compare registers
  69. ts[bwl] x        tst.[bwl] Dx        test register against 0
  70.  
  71. ig[bwl] num sym        addi.[bwl] #num,sym    increment global
  72. il[bwl] num off        addi.[bwl] #num,off(A6)    increment local
  73. irl num x        addi.l #num,Ax        increment register var
  74. ii[bwl] num a        addi.[bwl] #num,(Aa)    increment indirect
  75.  
  76. xtb x            ext.w Dx        extend byte to word
  77. xtw x            ext.l Dx        extend word to long
  78. xub x            andi.l #0xFF,Dx        unsigned extend byte to long
  79. xuw x            andi.l #0xFFFF,Dx    unsigned extend word to long
  80.  
  81.  
  82. Notes:
  83.  
  84. Labels and string identifiers are numbers that are re-used for every function.
  85. As labels and strings are used, the assembler keeps track of their use.  
  86. When the "efn" opcode is encountered, all the label forward references
  87. are fixed up and the label identifiers can then be re-used.  Strings are
  88. typically a forward reference, which is fixed up when the string is defined.
  89.  
  90. All the possible C operations are numbered by the compiler.  These numbers 
  91. are matched in the assembler to 68000 opcodes.
  92.  
  93.     1    or
  94.     2    exclusive or
  95.     3    and
  96.  
  97.     4    equal (comparison)
  98.     5    not equal (comparison)
  99.     6    less than (comparison)
  100.     7    greater than (comparison)
  101.     8    less than or equal (comparison)
  102.     9    greater than or equal (comparison)
  103.  
  104.     10    shift left
  105.     11    logical shift right
  106.     12    add
  107.     13    subtract
  108.     14    multiply
  109.     15    divide
  110.     16    mod
  111.  
  112.     17    logical negation
  113.     18    arithmetic negation
  114.     19    bitwise negation (eor #0xFFFFFFFF,reg)
  115.  
  116.     20    unsigned equal (comparison)
  117.     21    unsigned not equal (comparison)
  118.     22    unsigned low  (comparison)
  119.     23    unsigned high (comparison)
  120.     24    unsigned low or same (comparison)
  121.     25    unsigned high or same (comparison)
  122.  
  123.     26    arithmetic shift right (sign bit carried through)
  124.  
  125. If your favorite 68000 opcode does not appear in the above, you can resort
  126. to using the "=" facility to place opcodes in line in the text.  For example,
  127. you can get access to the LineA facilities with:
  128.  
  129. PutPixel(color, x, y) {
  130.     /* set up input LineA variables */
  131.     asm( = 40961 ); /* 40961 == 0xA001 */
  132. }
  133.  
  134. Arguments to opcodes can be set using =. or =$ codes.  For example,
  135.  
  136.     "move.l xxx,yyy" 
  137.  
  138. can be implemented in an intermediate code module as
  139.  
  140. = 9209        # opcode for move.l sym.l,sym.l
  141. =. xxx        # address of symbol xxx
  142. =. yyy        # address of symbol yyy
  143.  
  144. Please remember that all values in the intermediate code are 
  145. (long signed) decimal.  That certainly doesn't make the above easy,
  146. but you should be writing in C most the time anyway, right?
  147.